<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>编辑文章</title>
    <link href="${pageContext.request.contextPath}/static/semantic/semantic.min.css" rel="stylesheet">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/static/css/blog.css">
    <script src="${pageContext.request.contextPath}/static/js/jquery-3.4.1.js"></script>
</head>
<body>
<!--头部信息-->
<jsp:include page="head.jsp"/>
<!--中间内容-->
<div class="ui b-padding-tb b-contatiner">
    <div class="ui container segment">
        <div class="ui b-padding-tb-max b-border-radius">
            <!--文章数据管理-->
            <div class="ui card b-border-radius left b-manage" style="margin: auto !important;">
                <div class="content">
                    <div class="header">文章总数</div>
                    <div class="meta"></div>
                    <div class="ui divider"></div>
                    <div class="description">
                        <div class="ui statistics">
                            <div class="statistic">
                                <div class="value">
                                    ${manage.allArticle}
                                </div>
                                <div class="label">
                                    文章总数
                                </div>
                            </div>
                            <div class="statistic">
                                <div class="value">
                                    ${manage.publishArticle}
                                </div>
                                <div class="label">
                                    发表文章
                                </div>
                            </div>
                            <div class="statistic">
                                <div class="value">
                                    ${manage.allComment}
                                </div>
                                <div class="label">
                                    总评论数
                                </div>
                            </div>
                            <div class="statistic">
                                <div class="value">
                                    ${manage.allKind}
                                </div>
                                <div class="label">
                                    类别
                                </div>
                            </div>
                            <div class="statistic">
                                <div class="value">
                                    ${manage.allLabel}
                                </div>
                                <div class="label">
                                    标签
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="extra content">
                    <div class="ui fluid  buttons b-border-radius">
                        <a href="${pageContext.request.contextPath}/toRegister" class="ui button">账号注册</a>
                        <a class="ui button">标签管理</a>
                        <a class="ui button">类别管理</a>
                        <a href="${pageContext.request.contextPath}/toEdit" class="ui button icon">
                            <i class="plus icon"></i>文章添加
                        </a>
                    </div>
                </div>
            </div>

            <!--文章管理页-->
            <div class="b-margin-padding-label">
                <table class="ui selectable celled table center aligned striped">
                    <thead>
                        <tr>
                            <th>title</th>
                            <th>publish</th>
                            <th>编辑</th>
                            <th>发布</th>
                            <th>下架</th>
                            <th>删除</th>
                        </tr>
                    </thead>
                    <tbody>
                        <c:forEach items="${manage.articles}" var="article">
                            <tr>
                                <td>${article.title}</td>
                                <td>${article.publish}</td>
                                <td class="selectable">
                                    <a class="ui basic button" href="${pageContext.request.contextPath}/manage/edit/${article.id}">编辑</a>
                                </td>
                                <td class="selectable">
                                    <button aid="${article.id}" class="ui basic button publishBtn">发布</button>
                                </td>
                                <td class="selectable">
                                    <button aid="${article.id}" class="ui basic button unpublishBtn">下架</button>
                                </td>
                                <td class="selectable">
                                    <button aid="${article.id}" class="ui basic button deleteBtn">删除</button>
                                </td>
                            </tr>
                        </c:forEach>
                    </tbody>
<%--                    <tfoot class="full-width">--%>
<%--                        <tr>--%>
<%--                            <th colspan="4">--%>
<%--                                <a href="#" class="ui button basic">上一页</a>--%>
<%--                                <a href="#" class="ui button basic">下一页</a>--%>
<%--                            </th>--%>
<%--                        </tr>--%>
<%--                    </tfoot>--%>
                </table>
            </div>

            <div class="ui two column grid b-margin-padding-label">
                <!--标签管理-->
                <div class="ui column" style="padding: 1px !important;">
                    <table class="ui celled table selectable center aligned striped">
                      <thead>
                        <tr>
                            <th>id</th>
                            <th>标签</th>
                        </tr>
                      </thead>
                      <tbody>
                      <c:forEach items="${manage.labels}" var="label">
                          <tr>
                              <td>${label.id}</td>
                              <td>${label.label}</td>
                          </tr>
                      </c:forEach>
                      </tbody>
                        <tfoot>
                            <tr>
                                <th colspan="2">
                                    <form class="ui form" id="addLabel" action="${pageContext.request.contextPath}/manage/addLabel" method="post">
                                        <div class="ui inline field b-inline-margin">
                                            <div class="ui left icon input">
                                                <input name="label" type="text" placeholder="输入标签">
                                                <i class="tags icon"></i>
                                            </div>
                                            <button class="ui basic button">
                                                    添加标签
                                            </button>
                                        </div>
                                        <div class="ui error message" style="width: 200px !important;"></div>
                                    </form>
                                </th>
                            </tr>
                            <tr>
                                <th colspan="2">
                                    <form id="deleteLabel" class="ui form" action="${pageContext.request.contextPath}/manage/deleteLabel" method="post">
                                        <div class="ui icon inline field b-inline-margin">
                                            <div class="ui left icon input">
                                                <i class="tags icon"></i>
                                                <input name="id" type="text" placeholder="输入id">
                                            </div>
                                                <button class="ui basic button">
                                                    删除标签
                                                </button>
                                        </div>
                                        <div class="ui error message" style="width: 200px !important;"></div>
                                    </form>
                                    <c:if test="${labelerror}!=null">
                                        <div class="ui error message" style="width: 200px !important;"></div>
                                    </c:if>
                                </th>
                            </tr>
                        </tfoot>
                    </table>
                </div>
                <!--分类管理-->
                <div class="ui column" style="padding: 1px !important;" >
                    <table class="ui celled table selectable center aligned striped">
                        <thead>
                            <tr>
                                <th>id</th>
                                <th>类别</th>
                            </tr>
                        </thead>
                        <tbody>
                            <c:forEach items="${manage.kinds}" var="kind">
                            <tr>
                                <td>${kind.id}</td>
                                <td>${kind.kind}</td>
                            </tr>
                            </c:forEach>
                        </tbody>
                        <tfoot>
                            <tr>
                                <th colspan="2">
                                    <form id="addKind" class="ui form" action="${pageContext.request.contextPath}/manage/addKind" method="post">
                                        <div class="ui icon inline field b-inline-margin">
                                            <div class="ui left icon input">
                                                <i class="idea  icon"></i>
                                                <input name="kind" type="text" placeholder="输入类别">
                                            </div>
                                            <button class="ui basic button">
                                                添加类别
                                            </button>
                                        </div>
                                        <div class="ui error message" style="width: 200px !important;"></div>
                                    </form>
                                </th>
                            </tr>
                            <tr>
                                <th colspan="2">
                                    <form class="ui form" id="deleteKind" action="${pageContext.request.contextPath}/manage/deleteKind" method="post">
                                        <div class="ui icon inline field b-inline-margin">
                                            <div class="ui left icon input">
                                                <i class="idea  icon"></i>
                                                <input name="id" type="text" placeholder="输入id">
                                            </div>
                                            <button class="ui basic button">
                                                删除类别
                                            </button>
                                        </div>
                                        <div class="ui error message" style="width: 200px !important;"></div>
                                    </form>
                                </th>
                            </tr>
                        </tfoot>
                        <form id="publishform" method="post"></form>
                        <form id="unpublishform" method="post"></form>
                        <form id="deleteform" method="post"></form>

                    </table>
                </div>

            </div>

        </div>
    </div>



</div>


<!--底部信息-->
<footer>


</footer>
<script>

</script>


<script>
    $('.ui.selection.dropdown').dropdown();

    //发布操作
    $(".publishBtn").click(function () {
        $("#publishform").attr("action","${pageContext.request.contextPath}/manage/publishArticle/"+$(this).attr('aid')).submit();
        return false;
    });
    //下架操作
    $(".unpublishBtn").click(function () {
        $("#unpublishform").attr("action","${pageContext.request.contextPath}/manage/unpublishArticle/"+$(this).attr('aid')).submit();
        return false;
    });
    //删除
    $(".deleteBtn").click(function () {
        $("#deleteform").attr("action","${pageContext.request.contextPath}/manage/deleteArticle/"+$(this).attr('aid')).submit();
        return false;
    });

    $("#addLabel").form({
        on:"blur",
        fields:{
            label:{
                identifier:'label',
                rules:[{
                    type:'empty',
                    prompt:'标签不能为空'
                },
                    {
                        type:'minLength[2]',
                        prompt:'标签过短'
                    }]
            }
        }
    });
    $("#deleteLabel").form({
        on:"blur",
        fields:{
            id:{
                identifier:'id',
                rules:[{
                    type:'empty',
                    prompt:'标签id不能为空'
                }]
            }
        }
    });
    $("#addKind").form({
        on:"blur",
        fields:{
            kind:{
                identifier:'kind',
                rules:[{
                    type:'empty',
                    prompt:'类别不能为空'
                },{
                    type:'minLength[2]',
                    prompt:'类别过短'
                }]
            }
        }
    });
    $("#deleteKind").form({
        on:"blur",
        fields:{
            label:{
                identifier:'id',
                rules:[{
                    type:'empty',
                    prompt:'id不能为空'
                }]
            }
        }
    });

</script>
</body>
</html>